package top.fyukina.fymil.parsers;

import org.dom4j.Element;
import top.fyukina.fymil.DataType;
import top.fyukina.fymil.internal.exps.Expression;
import top.fyukina.fymil.elements.Environment;
import java.util.HashMap;
import java.util.Map;

public class ExpressionParser implements
        RegistrableParser<Object, String, Expression<?>> {
    private static final Map<String, Expression<?>> expLib
            = new HashMap<>();
    @Override
    public Map<String, Expression<?>> getLib() {
        return expLib;
    }
    @Override
    public Object parse(Element tag, Environment env) {
        Expression<?> exp = expLib.get(tag.getName());
        if (exp == null) {
            return DataType.getDefaultNonType();
        }
        return exp.parse(tag, env);
    }
    @Override
    public ParserType registerName() {
        return ParserType.EXP;
    }
}